$(function(){
	$("#sendBtn").click(send_letter);
	$(".close").click(delete_msg);
});

function send_letter() {
	let toName = $("#recipient-name").val();
	let content = $("#message-text").val();

    $.post(
        CONTEXT_PATH + "/message/send",
        {toName, content},
        function (data) {
            if (data.code == 0) {
                $("#sendModal").modal("hide");
                showHit(data.msg, ()=>location.reload());
            }
            showHit(data.msg);
        }
    );
}

function showHit(content, callBack){
    $("#hintBody").text(content);
    $("#hintModal").modal("show");
    setTimeout(function() {
        $("#hintModal").modal("hide");
        if (callBack) { callBack(); }
    }, 2000);
}

function delete_msg() {
	// TODO 删除数据
	$(this).parents(".media").remove();
}